<template>
    <div>
        <div class="header" :style="opacityStyle">
            <div class="header-left">
                <router-link to="/">
                    <div class="iconfont back-icon">&#xe624;</div>
                </router-link>
            </div>
            <div class="header-middle">
                景点详情
            </div>
        </div>
    </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      var scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop
      if (scrollTop < 120) {
        let opacity = scrollTop / 120
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {
          opacity
        }
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeDestroy () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
.header {
    height: 0.86rem;
    width: 100%;
    background: #00bcd4;
    color: #fff;
    line-height: 0.86rem;
    text-align: center;
    position: fixed;
    top: 0;
    z-index: 9999;
}
.header-left {
    width: 0.64rem;
    float: left;
}

.iconfont {
    color: #fff;
}
</style>
